Repository navigation
perf(durable): cache each type's full spelling - #273
Merged
Merged
Conversation
Contributor
Author
Review findingsThe AI reviewers' pass over this change checked every review label. They raised one plausible issue, which is now fixed:
Two candidates were refuted:
|
Contributor
Author
Decisions for Temple to ratifyI made these calls in this PR. Each is a suggestion for you to confirm or change.
|
This was referenced Nov 18, 2026
reka18
force-pushed
the
fix/durable-stopactor-actor-sets
branch
from
November 25, 2026 20:42
78bcfe1 to
7cd223c
Compare
Every settle, park and replay type check asks a result's type name, and an unnamed type's spelling walks its whole shape, but the same handful of result types settle again and again. fullTypeName now caches each type's spelling on its reflect.Type - two reflect.Types compare equal exactly when the types are identical, so a cached spelling is always the one its own type spells - and the spelling itself doesn't change. The cache is capped at 4096 entries: past the cap a type is spelled and returned unstored, so runtime-minted reflect.StructOf types can't grow it without end. Item 1, the settledJSON holder, moved to #271 for Temple's ruling, since Option B would put a recording concern in state's public signatures. Item 3 stays as it is: the full spelling keeps the replay type check strict. Closes #255. Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
The cache's own concurrency had no test: no test spells types from two goroutines at once, so simultaneous first misses on one type, hits under load and a fill racing the cap were unpinned - a regression in the counter or the cap check would ship unnoticed through the -race gate. A new probe runs every spelling concurrently: each goroutine spells more distinct StructOf-minted structs than a lowered cap admits, all built from the same shared types, then the shared types themselves. Whatever the interleaving, every spelling must be its type's own, the counter must count each stored entry exactly once, and the fill can pass the cap only by one in-flight store per goroutine that raced it. The benchmark's comment now says what it measures: the first iteration spells and stores, every one after - the steady state for a settling run - is a hit, so the reported number is the hit, not the first spelling. Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
reka18
force-pushed
the
refactor/durable-service-result-cleanups
branch
from
November 25, 2026 23:06
700dac5 to
774cc37
Compare
reka18
marked this pull request as ready for review
November 25, 2026 23:13
joshua-temple
approved these changes
Nov 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
typeNamespells a result's full Go type, with import paths kept inside unnamed composites. It runs on every service settle and every replayed one, and it walkedreflectrecursively each time. The spelling is now cached perreflect.Type, in a cache eachRunnerowns, so there's no package-level state. A cached entry is always the right spelling, because tworeflect.Typevalues are equal exactly when the types are identical.The cache is capped. A host that mints result types at runtime with
reflect.StructOfcould otherwise grow it without bound. Past the cap, a type is spelled and not stored.WithResultTypeAliasandStateAthave no Runner in reach, so they spell uncached. That changes nothing they return.Behavior doesn't change, and there's no new API and no CHANGELOG entry.
The other two items in #255
settledJSONholder moved to durable: keep or remove the settledJSON holder between a settle and its journal Record #271 for a ruling. Removing it would change exportedstatesignatures.fullTypeName's length stays. The shorter form spells short package names inside composites, sostruct{ R alpha.Result }andstruct{ R beta.Result }would match, which loosens the replay type check. Five tests pin the strict form.Numbers
Medians of
-count=5 -benchmem, before and after:FullTypeName_DeepUnnamedType(new)RunService_SettleRecover_ServiceResults(200 settles)Tests
The type-name and parked-type tests check exact spellings on cache hits. Keying the cache on
Kindinstead of the type fails all three type-name tests. Three new tests:Checks
mage checkpasses in every module (go1.27.4)go test -race ./durable/...Closes #255